package com.teradata.multithread.cdl;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;

import java.util.concurrent.*;

/**
 * @author: lyndon
 * @version: 1.0
 * @date: 2019/2/18
 */
public class ThreadPoolConfig {

    public static ExecutorService makePoolByFactory() {
        final ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("demo-pool-%d").build();

        final ThreadPoolExecutor threadPoolExecutor =
                new ThreadPoolExecutor(5, 200, 0L, TimeUnit.MICROSECONDS,
                        new LinkedBlockingDeque<Runnable>(1024),
                        nameThreadFactory,
                        new ThreadPoolExecutor.AbortPolicy());
        return threadPoolExecutor;
    }


    public static ExecutorService makePoolByScheduler() {
        final ScheduledThreadPoolExecutor executorService = new ScheduledThreadPoolExecutor(3,
                new BasicThreadFactory.Builder().namingPattern("example-schedule-pool-%d").daemon(true).build());

        return executorService;
    }

}
